package com.bdqn.cloud.t330.controller;

import com.bdqn.cloud.t330.entity.Dto;
import com.bdqn.cloud.t330.service.UserRemoteClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
public class UserController {

    //服务提供者的controller地址
    //private static final String USER_SERVICE_URL = "http://localhost:8001/list";
    private static final String USER_SERVICE_URL = "http://CLOUD-SERVICE-USER/list";

    //@Autowired 在spring容器中查找org.springframework.web.client.RestTemplate类型的实例
    //在spring容器中查找restTemplate名字的实例
    @Resource
    private RestTemplate restTemplate;

    //导入我们针对服务提供者定义的接口
    @Resource
    private UserRemoteClient userRemoteClient;


    @RequestMapping("/service/user/feign")
    public Dto getUserListFeign() {
        System.out.println("feign............");
        //调用远程的controller,restful的调用,通过feign这种声明式的远程调用
        return userRemoteClient.list();
    }



    @RequestMapping("/service/user/list")
    public Dto getUserList() {
        ResponseEntity<Dto> entity = restTemplate.getForEntity("http://CLOUD-SERVICE-USER/list", Dto.class);
        return entity.getBody();
    }
}
